package org.adorsys.aderp.cash.work.encashment.redirect;

import java.util.logging.Level;
import java.util.logging.Logger;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * the developer of a module will have to consult the
 * aderp-cash-redirect.properties . He need to to send a redirect with this
 * {@value requestToHandleValue}, then been redirect to another module.
 * 
 * @author "w2b"
 * 
 */

@RequestMapping(value = "/clienttoaderpcash/processpayment")
@Controller
public class ClientToAderpCashController {
	@Resource
	private RedirectorBean redirectorBean;
	Logger logger = Logger.getLogger("client_to_aderp-cash_logger");
	
	@RequestMapping(method = RequestMethod.GET)
	public String redirect(@RequestParam("data")String dataParam,HttpServletRequest request, Model uiModel) {
		
		logger.log(Level.INFO," preparing for redirection ... ");
		Assert.notNull(redirectorBean, "The redirection bean might not be null");
		redirectorBean.setData(dataParam);
		redirectorBean.setModuleCallingUrl(request.getContextPath()+""+request.getQueryString());
		logger.log(Level.INFO," ready to redirect ... ");
		return redirectorBean.getAderpCashUrl()+"?data="+redirectorBean.getData()+"&moduleCallingUrlValue="+redirectorBean.getModuleCallingUrl();
	}
}
